package com.goldplusgold.support.lib.base.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;

/**
 * Created by Administrator on 2017/8/7.
 */

public class BaseNetWorkActivity extends BaseActivity {

    private List<Call> lists ;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        lists = new ArrayList<Call>() ;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        cancelAll();
        clearCallList();
    }


    public void addCall(Call call){
        lists.add(call) ;
    }

    public void addAllCall(List<Call> calls){
        lists.addAll(calls);
    }

    public void cancel(Call call){
        for(Call c :lists){
            if(c == call){
                c.cancel();
            }
        }
    }

    public void cancelAll(){
        for(Call c : lists){
            c.cancel();
        }

    }

    public void clearCallList(){
        lists.removeAll(lists);
    }

}
